
var data = [];

$(function() {	
	Tip.emp('借款人');
});

var BorrowMy = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},			
			
			"添加": function() {				
				if (!confirm("确认是否添加？")) {
					return false;
				}				
	
				var form = $("#form_add")[0];
	
				var body = { };				
				body.emp = form.emp.value;
				
				body.name = form.name.value;
				body.content = form.content.value;
				
				body.currency = form.currency.value;
				body.amount = form.amount.value;
				
				body.payment = form.payment.value;
				
				var payment_x = {};
				if (body.payment == '2') {
					payment_x.bank = form.x_bank.value;
					payment_x.name = form.x_name.value;
					payment_x.code = form.x_code.value;
					payment_x.content = form.x_content.value;
				}
				
				body.payment_x = $.toJSON(payment_x);
				
				body.type = form.type.value;
				body.begin = form.date1.value;
				body.end = form.date2.value;
				body.day = form.day.value;
									
				$(this).dialog("close");
	
				$.post('finance.php?do=BorrowMy.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
	
	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'finance.php?do=BorrowMy.edit&id=' + id;
		var c2 = 'finance.php?do=BorrowMy.view&id=' + id;
				
		var a1 = ['编辑信息', 'url', 'BorrowMy.dialog_edit_', '600x380'];	
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '600x380'];
		
		if (status == '1') {
			var d1 = 'finance.php?do=BorrowMy.verify&id=' + id;
			var b1 = ['审核信息', 'url', 'BorrowMy.dialog_verify', '650x400'];
			
			var s = d1 + ", " + c1 + ", " + c2;

			return this.popup_(e, [b1, a1, a2], s);
		}
		
		if (status == '2') {
			var s = c1 + ", " + c2;

			return this.popup_(e, [a1, a2], s);
		}

		var s = c2;

		return this.popup_(e, [a2], s);
	},
	
	popup_: function (e, a, s) {
		var id = $.cookie('id_');
		
		var c1 = 'finance.php?do=BorrowMy.upload&id=' + id;
		var a1 = ['上传附件', 'url', 'Common.dialog_upload', '600x420'];
		
		var c2 = 'finance.php?do=BorrowMy.view&print=print&id=' + id;
		var a2 = ['打印信息', 'url', 'Common.dialog_view_', '742x508'];
		
		var c3 = 'finance.php?do=BorrowMy.copy&id=' + id;
		var a3 = ['复制信息', 'url', 'BorrowMy.dialog_copy_', '700x450'];
		
		s += ", " + c1 + ", " + c2 + ", " + c3;
		
		a.push(a1);
		a.push(a2);
		a.push(a3);
		
		return popup(e, a, s);
	},
	
	dialog_verify: function (url, title, xy) {
		result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() { 
				$(this).dialog("close");
			},		

			"不提交": function() {
				if (!confirm("确认是否不提交借款？")) {
					return false;
				}				
				
				var form = $("#form_edit")[0];
				
				var body = {};
				body.id = form.id.value;
				body.content = form.content.value;
				body.status = 9;
				
				$(this).dialog("close");
				
				var url = 'finance.php?do=BorrowMy.verifyPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			},
			
			"提交": function() {
				if (!confirm("确认是否提交借款？")) {
					return false;
				}				

				var form = $("#form_edit")[0];
				
				var body = {};
				body.id = form.id.value;
				body.content = form.content.value;
				body.status = 2;
				
				$(this).dialog("close");

				var url = 'finance.php?do=BorrowMy.verifyPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {			
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"提交": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
				
				var body = { };
				body.id = form.id.value;
				body.emp = form.emp.value;
				
				body.name = form.name.value;
				body.content = form.content.value;
				
				body.currency = form.currency.value;
				body.amount = form.amount.value;
				
				body.payment = form.payment.value;
				
				var payment_x = {};
				if (body.payment == '2') {
					payment_x.bank = form.x_bank.value;
					payment_x.name = form.x_name.value;
					payment_x.code = form.x_code.value;
					payment_x.content = form.x_content.value;
				}
				
				body.payment_x = $.toJSON(payment_x);
				
				body.type = form.type.value;
				body.begin = form.date1.value;
				body.end = form.date2.value;
				body.day = form.day.value;
										
				$(this).dialog("close");
	
				var url = 'finance.php?do=BorrowMy.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {			
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"复制": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
				
				var body = { };
				body.emp = form.emp.value;
				
				body.name = form.name.value;
				body.content = form.content.value;
				
				body.currency = form.currency.value;
				body.amount = form.amount.value;
				
				body.payment = form.payment.value;
				
				var payment_x = {};
				if (body.payment == '2') {
					payment_x.bank = form.x_bank.value;
					payment_x.name = form.x_name.value;
					payment_x.code = form.x_code.value;
					payment_x.content = form.x_content.value;
				}
				
				body.payment_x = $.toJSON(payment_x);
				
				body.type = form.type.value;
				body.begin = form.date1.value;
				body.end = form.date2.value;
				body.day = form.day.value;
										
				$(this).dialog("close");
	
				var url = 'finance.php?do=BorrowMy.addPost';
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	}
};
